//index.js
//获取应用实例
const app = getApp()
var utl = require('../../utils/util.js');
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    items:['remember'],
    ischecked:true,
    jrfwArr:[],
    ntice:'',
    nohot:false
  },
 
  onLoad: function (e) {
    console.log(e);
    var loginend = e.section;
    if (loginend){
      this.queryTop();
      this.queryNotice();
    }else{
      wx.redirectTo({
        url: '/pages/login/index',
      })
    }
  },
  //账单查询
  orderAction:function(){
    const status = app.globalData.userData.status;
    if (status == '30') {//注册用户
      wx.navigateTo({
        url: '/pages/regist/userredit',
      })
    } else if (status == '60') {
      wx.navigateTo({
        url: '/pages/orderlist/index',
      })
    } else {
      var err = utl.userStatus(status);
      wx.showModal({
        title: '提示',
        content: err,
        showCancel: false,
      })
    }

  },
  //收款
  gopayAction:function(){
    const status = app.globalData.userData.status;
    if (status == '30'){//注册用户
      wx.navigateTo({
        url: '/pages/regist/userredit',
      })
    }else if(status == '60'){
      wx.navigateTo({
        url: '/pages/checkm/index',
      })
    }else{
      var err = utl.userStatus(status);
      wx.showModal({
        title: '提示',
        content: err,
        showCancel:false,
      }) 
    }
    
  },
  //查询消息
  queryNotice:function(){
    wx.showLoading({
      title: '请求中...',
    })
    utl.serverToken('/epay_apps/push/getPushMsgList', { 'pageNum': 1, 'pageSize': 1, "msgRemark": 1 }, (err, res) => {
      wx.hideLoading();
      var notice = res.response.recordList;
      if(notice.length==1){
        var tish = notice[0].content;
        this.setData({
          ntice:tish,
        })
      }
    })
  },
  //查询
  queryTop:function(){
    utl.serverToken('/epay_apps/login/homePage', {}, (err, res) => {
      wx.hideLoading();
      if (err) {
        wx.showToast({
          title: err,
          icon: 'none',
          duration: 2000
        })
        return;
      }

      var jrf = res.response.expandConfigInfo;
      if(jrf.length>8){
        var subArr = jrf.slice(0,7);
        var more = [{ 'businessName': '更多', 'imagePath':'/pages/images/home_ic_more.png'}];
        var neew = subArr.concat(more);
        this.setData({
          jrfwArr: neew
        })
      }else{
        this.setData({
          jrfwArr: jrf
        })
      } 
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  radioChange:function(e){
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    var ischeck = this.data.ischecked;
    ischeck = !ischeck;
    this.setData({
      ischecked:ischeck
    })
  },
  jumdetail:function(e){
    const dex = e.currentTarget.dataset.info;
    var arr = this.data.jrfwArr;
    var gerp = arr[dex];
    var name = gerp.businessName;
    if(name == '更多'){
      wx.navigateTo({
        url: '/pages/more/index',
      })
    }else{
      var bslink = gerp.pagePath;
      var str1 = encodeURIComponent(bslink);
      wx.navigateTo({
        url: '/pages/more/profit?linkurl=' + str1,
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })
    }
  }
})
